// pages/mes/follow/follow.js
const app = getApp();
import Toast from '../../../component/toast/toast';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        hasMore:true,
        pageSize: 10,
        pageIndex: -1,
        followList:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getFollowList();
    },
    getFollowList(){
        let that = this;
        if (!that.data.hasMore) return;
        let pageI = ++that.data.pageIndex;
        let data = {
            pageSize: that.data.pageSize,
            pageIndex: pageI,
            userInfoId: app.userInfo.Id,
        };
        that.setData({
            pageIndex: pageI
        });
        wx.request({
            url: app.globalData.serverAddress.getFollowList,
            data: data,
            header: {
                'Authorization': "Bearer " + app.globalData.token
            },
            success: function (res) {
                console.log("getFollowList" , res);
                if (res.statusCode == 200) {
                    if (res.data.CodeStatus == 20000) {
                        let count = res.data.BodyContent.TotalCount;
                        let flag = (that.data.pageIndex + 1) * that.data.pageSize < count;
                        // console.log(flag);
                        let newList = [];
                        if (res.data.BodyContent.List){
                            newList = that.data.followList.concat(res.data.BodyContent.List);
                        }
                        that.setData({
                            followList: newList,
                            hasMore: flag
                        });
                    } else {
                        that.setData({
                            hasMore: false
                        });
                    }
                }
            },
            fail: function (res) {
                // console.log(JSON.stringify(res));
                let msg = res.data.Message;
                if(msg){
                    Toast(msg);
                }else{
                    Toast("请求失败，请检查网络！");
                }
            },
            complete: function (res) {
                wx.hideLoading();
            }
        });
    },


    /**
     * 事件监听
     */
    selectItem(e) {
        let index = e.currentTarget.dataset.index;
        let id = this.data.followList[index].FollowUserInfoId
        wx.navigateTo({
            url: '/pages/issusUserInfo/issusUserInfo?userInfoId=' + id,
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        this.getFollowList();
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})